@extends('admin.layout')

@section('title', $title)

@section('content')
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                商品管理
                <small>商品列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="active">商品列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">商品列表</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            @if( session('info') )
                            <div id="jg" class="callout callout-info">
                            <h4>{{ session('info')}}</h4>
                            </div>    
                            @endif
                            <table id="example2" class="table table-bordered table-hover">
                           		 <form action="{{ url('admin/goods/list') }}" method="get">
									<div class="form-group">
										<div class="row">
											<div class="col-md-2">
		                                    </div>
		                                    <div class="col-md-offset-7 col-md-3">
		                                    	<div class="input-group input-group-sm">
		                               				<input type="text" name="name" class="form-control" value="{{ $request['name'] or ''}}" placeholder="商品名称">
							                    	<span class="input-group-btn">
							                     	   <button class="btn btn-info btn-flat">商品查询</button>
							                   		</span>
						                   		</div>
	                           				 </div>
	                                    </div>
	                                </div>
                               	</form>
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>商品名称</th>
                                    <th>商品价格</th>
                                    <th>商品logo</th>
                                    <th>商品主分类</th>
                                    <th>商品扩展分类</th>
                                    <th>添加时间</th>
									<th>上架状态</th>
									<th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $v)
                                <tr>
                                    <td>{{ $v -> id }}</td>
                                    <td>{{ $v -> goods_name }}</td>
                                    <td>￥{{ $v -> goods_price }}</td>
                                    <td>
                                    @if($v->logo != '')
                                    <img src="{{ url('/uploads/goods_pic/')}}/{{$v -> logo }}" width="70" height="70">
                                    @else
                                    无
                                    @endif
                                    </td>
                                    <td>{{ $v -> cname }}</td>
                                     <td>{{ $v -> ext_cname }}</td>
                                    <td>{{ date('Y-m-d H:i:s', $v -> addtime) }}</td>
                                    <td class="td" value="{{ $v -> id }}">
                                    @if($v -> is_on_sale == 1)
                                    上架
                                    @else
                                    下架
                                    @endif
                                    </td>
                                    <td><a href="{{ url('admin/goods/edit') }}/{{ $v -> id }}">编辑</a>|<a onclick=" return confirm('确认删除吗')" href="{{ url('admin/goods/delete') }}/{{ $v -> id }}">删除</a></td>
                                </tr>
                                @endforeach
                                </tbody>
                            </table>
                            {!! $data->appends($request)->render() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
<script type="text/javascript">
    window.onload = function(){
        setInterval(function(){
            $('#jg').slideUp();
        },3000);
    $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
    $('.td').on('click',function(){
        var id = $(this).attr('value');
        var a = $(this);
        $.ajax({
            type:'POST',
            url:"{{ url('admin/goods/ajaxTop') }}",
            data:{id:id},
            success:function(data)
            {
                if(data == 0)
                {
                    a.text('下架');
                }else if(data == 1)
                {
                    a.text('上架');
                }
            },
            error:function()
            {
                alert('错误');
            }
        });
    });
}

</script>
@endsection